package com.example.jeong.yuejian10.Adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;


import com.example.jeong.yuejian10.Bean.EnterMatchBean;
import com.example.jeong.yuejian10.R;
import com.squareup.picasso.Picasso;

import java.util.List;

import static com.example.jeong.yuejian10.constant.Constant.MATCH_PHOTO_URL;


public class MyMatchOrderListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{
    private Context mContex;
    private List mDataList;
    private ViewHolder viewHolder;
    private LayoutInflater mLayoutInflater;

    public MyMatchOrderListAdapter(Context mContext, List mDataList) {
        this.mContex =  mContext;
        this.mDataList = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = mLayoutInflater.from(parent.getContext()).
                inflate(R.layout.cardview_my_order, parent, false);
        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final EnterMatchBean entity = (EnterMatchBean) mDataList.get(position);
        if (null == entity)
            return;

        ViewHolder viewHolder = (ViewHolder) holder;
        viewHolder.createtime.setText(entity.getCreatetime());
        viewHolder.m_name.setText(entity.getM_name());
        viewHolder.m_time.setText(entity.getM_time());
        viewHolder.m_price.setText("￥"+entity.getM_price()+"");
        String m_pic = MATCH_PHOTO_URL+entity.getM_picture();
        //System.out.print("pic");
        if (!m_pic.equals("")) {
            Picasso.with(mContex).load(m_pic).error(R.drawable.ic_add).into(viewHolder.m_pic);
        }

    }


    @Override
    public int getItemCount() {
        return mDataList.size();
    }
    public class ViewHolder extends RecyclerView.ViewHolder {
        ImageView m_pic;
        TextView createtime,m_name,m_price,m_time;

        public ViewHolder(View itemView) {
            super(itemView);
            createtime = (TextView) itemView.findViewById(R.id.createtime);
            m_time = (TextView) itemView.findViewById(R.id.time);
            m_name = (TextView) itemView.findViewById(R.id.name);
            m_price = (TextView) itemView.findViewById(R.id.price);
            m_pic= (ImageView) itemView.findViewById(R.id.pic);

        }
    }
}